package me.maiz.babyisland.web;

import me.maiz.babyisland.es.entity.ProductDocument;
import me.maiz.babyisland.service.SearchService;
import me.maiz.babyisland.web.form.SearchForm;
import lombok.extern.slf4j.Slf4j;
import me.maiz.babyisland.es.entity.ProductDocument;
import me.maiz.babyisland.service.SearchService;
import me.maiz.babyisland.web.form.SearchForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Slf4j
public class SearchController {

    @Autowired
    private SearchService searchService;

    @RequestMapping("/search")
    public String search(SearchForm form, ModelMap modelMap){
        log.info("搜索{}",form);
        Page<ProductDocument> result = searchService.search(form.getKeyWord(), form.getCategoryId(), form.getPageIdx(), form.getPageSize(), form.getSortField(), form.getSortDirection());
        modelMap.addAttribute("result",result);
        return "home";
    }



}
